package com.kedacom.demo.sendemail.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.kedacom.demo.emailgateway.model.Email;
import com.kedacom.demo.emailgateway.service.EmailGatewayClientProxy;

public class SendEmail {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	public static void main(String[] args) {
		SendEmail send = new SendEmail();
		send.send();
		// send.sendError();

	}

	private void send() {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
		EmailGatewayClientProxy emailGatewayClientProxy = (EmailGatewayClientProxy) context
				.getBean("emailGatewayClientProxy");
		Email email = new Email();
		email.setCompanyMoid("10000001");
		email.setSubject("测试");
		// email.setTo("wengxiongfei@kedacom.com,tt@kedacom.com,zhongruibo@kedacom.com,wuyuelong@kedacom.com,aa@kedacom.com");
		email.setTo("wengxiongfei@kedacom.com,tt@kedacom.com,aa.kkk.com");
		email.setText("测试客户端发送邮件");
		emailGatewayClientProxy.send(email);
	}

	private void sendError() {
		ClassPathXmlApplicationContext context;
		context = new ClassPathXmlApplicationContext("/applicationContext.xml");
		EmailGatewayClientProxy emailGatewayClientProxy = (EmailGatewayClientProxy) context
				.getBean("emailGatewayClientProxy");

		Email email = new Email();
		email.setCompanyMoid("1000000");
		email.setSubject("测试");
		email.setTo("test@kedacom.com");
		email.setText("测试客户端发送邮件");
		try {
			emailGatewayClientProxy.send(email);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
